package com.cloud.minioService.controller;

import com.cloud.minioService.utils.SampleUtil;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhozixiong
 * @date 2023/03/20
 */
@RestController
@RequestMapping("/phone")
public class PhoneController {

    @Autowired
    private DefaultKaptcha defaultKaptcha;

    @Value("${aliyun.sms.accessKeyId}")
    private String accessKeyId;

    @Value("${aliyun.sms.accessKeySecret}")
    private String accessKeySecret;

    @GetMapping("/code/{phone}")
    public String code(@PathVariable String phone) throws Exception {
        //生成验证码
        String code = defaultKaptcha.createText();
        //发送短信
        SampleUtil.send(phone, code, accessKeyId, accessKeySecret);
        //返回验证码
        return code;
    }
}
